package com.ezzd.service.impl;

import com.ezzd.EnmuInfo;
import com.ezzd.dao.DetailsDao;
import com.ezzd.pojo.TbDetails;
import com.ezzd.service.DetailsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

/**
 * @description tb_details
 * @author 被遗忘的湫
 * @date 2022-08-05
 */
@Service
@Transactional
public class DetailsServiceImpl implements DetailsService {

    @Resource
    private DetailsDao detailsDao;


    @Override
    public Object insert(TbDetails tbDetails) {

        // valid
        if (tbDetails == null) {
            return EnmuInfo.Fail;
        }

        detailsDao.insert(tbDetails);
        return EnmuInfo.Success;
    }


    @Override
    public Object delete(int id) {
        int ret = detailsDao.delete(id);
        return ret>0?EnmuInfo.Success:EnmuInfo.Fail;
    }


    @Override
    public Object update(TbDetails tbDetails) {
        int ret = detailsDao.update(tbDetails);
        return ret>0?EnmuInfo.Success:EnmuInfo.Fail;
    }


    @Override
    public TbDetails load(int id) {
        return detailsDao.load(id);
    }


    @Override
    public PageInfo<TbDetails> pageList(int pageNum, int pagesize) {

        PageHelper.startPage(pageNum, pagesize);
        List<TbDetails> pageList = detailsDao.pageList();

        PageInfo<TbDetails> pageInfo = new PageInfo<>(pageList);

        return pageInfo;
    }

}
